<!-- user表单弹框 -->
<form id="bapi-form" lay-filter="bapi-form" class="layui-form model-form">
    <input name="bapiId" type="hidden"/>
    <input name="count" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input name="bapiName" placeholder="请输入名称" type="text" class="layui-input" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分组</label>
        <div class="layui-input-block">
            <select name="group">
                <option value="">--请选择--</option>
                <option value="MM">采购</option>
                <option value="PP">物流</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="state" value="1" title="正常" checked/>
            <input type="radio" name="state" value="0" title="禁用"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <input name="description" placeholder="请输入描述信息" type="text" class="layui-input" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="bapi-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['form', 'admin'], function () {
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;

        form.render('radio');
        form.render('select');

        var url = 'sap/bapi/add';
        // 回显bapi数据
        var bapi = admin.getTempData('t_bapi');
        if (bapi) {
            $('input[name="bapiName"]').attr('readonly', 'readonly');
            url = 'sap/bapi/update';
            bapi.state = bapi.state.toString();
            form.val('bapi-form', bapi);
        };

        // 表单提交事件
        form.on('submit(bapi-form-submit)', function (data) {
            layer.load(2);
            $.post(url, data.field, function (data) {
                layer.closeAll('loading');
                if (data.code == 200) {
                    layer.msg(data.msg, {icon: 1});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2});
                }
            });
            return false;
        });
    })
</script>